package com.qf.controller;


import com.qf.bean.AjaxMessage;
import com.qf.entity.Address;
import com.qf.service.IAddressService;
import com.qf.service.impl.AddressServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.management.remote.JMXAddressable;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lcx
 * @since 2020-09-03
 */
@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    IAddressService addressService;

    @PostMapping("/update")
    public AjaxMessage updateAddress(@RequestBody Address address){
        AjaxMessage ajaxMessage=new AjaxMessage();
        addressService.updateAddress(address);
        ajaxMessage.setMsg("success");
        ajaxMessage.setStatus(1);
        return ajaxMessage;
    }

    @PostMapping("/add")
    public AjaxMessage addAddress(@RequestBody Address address,String token){
        AjaxMessage ajaxMessage=new AjaxMessage();
        Integer uid = addressService.getId(token);
        addressService.addAddress(address,uid);
        ajaxMessage.setMsg("success");
        ajaxMessage.setStatus(1);
        return ajaxMessage;
    }
    @PostMapping("/get")
    public AjaxMessage getAddress(String token){

        AjaxMessage ajaxMessage=new AjaxMessage();
        Integer id = addressService.getId(token);
        List<Address> address = addressService.getAddress(id);
        ajaxMessage.setMsg("success");
        ajaxMessage.setResult(address);
        ajaxMessage.setStatus(1);
        return ajaxMessage;
    }

}
